home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / include / RCS / spriteTime.h,v < prev    next >
Encoding:
Text File  |  1992-05-11  |  6.9 KB  |  330 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.4.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     92.05.11.15.24.22;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.4;
  13.  
  14. 1.4
  15. date     90.09.11.14.40.15;  author kupfer;  state Exp;
  16. branches 1.4.1.1;
  17. next     1.3;
  18.  
  19. 1.3
  20. date     89.06.23.11.30.25;  author rab;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.07.29.18.05.57;  author ouster;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.06.21.16.34.14;  author ouster;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34. 1.4.1.1
  35. date     91.08.15.21.47.02;  author kupfer;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @@
  42.  
  43.  
  44. 1.5
  45. log
  46. @Add Time_ToMs, Time_Average.
  47. @
  48. text
  49. @/*
  50.  * time.h --
  51.  *
  52.  *     External definitions for the time utility routines.
  53.  *
  54.  * Copyright 1986, 1988 Regents of the University of California
  55.  * Permission to use, copy, modify, and distribute this
  56.  * software and its documentation for any purpose and without
  57.  * fee is hereby granted, provided that the above copyright
  58.  * notice appear in all copies.  The University of California
  59.  * makes no representations about the suitability of this
  60.  * software for any purpose.  It is provided "as is" without
  61.  * express or implied warranty.
  62.  *
  63.  * rcsid: $Header: /sprite/src/lib/include/RCS/spriteTime.h,v 1.4 90/09/11 14:40:15 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)
  64.  */
  65.  
  66. #ifndef _SPRITETIME
  67. #define _SPRITETIME
  68.  
  69. #ifndef _SPRITE
  70. #include "sprite.h"
  71. #endif
  72.  
  73. /* DATA STRUCTURES */
  74.  
  75. /*
  76.  *  Definition of a time value.
  77.  */
  78.  
  79. typedef struct {
  80.     int    seconds;
  81.     int    microseconds;
  82. } Time;
  83.  
  84. typedef struct {
  85.     int year;
  86.     int month;
  87.     int dayOfYear;
  88.     int dayOfMonth;
  89.     int dayOfWeek;
  90.     int    hours;
  91.     int    minutes;
  92.     int    seconds;
  93.     int localOffset;
  94.     Boolean dst;
  95. } Time_Parts;
  96.  
  97. /* CONSTANTS */
  98.  
  99. /*
  100.  *  The number of microseconds in one second and one millisecond.
  101.  */
  102.  
  103. #define ONE_SECOND        1000000
  104. #define TENTH_SECOND        100000
  105. #define HUNDREDTH_SECOND    10000
  106. #define ONE_MILLISECOND        1000
  107.  
  108. /*
  109.  *  Length of buffers required by the Time conversion routines.
  110.  */
  111.  
  112. #define TIME_CVT_BUF_SIZE 30
  113.  
  114. /*
  115.  *  Frequently used time values.
  116.  */
  117.  
  118. extern Time time_ZeroSeconds;
  119. extern Time time_OneMicrosecond;
  120. extern Time time_OneMillisecond;
  121. extern Time time_TenMilliseconds;
  122. extern Time time_HundredMilliseconds;
  123. extern Time time_HalfSecond;
  124. extern Time time_OneSecond;
  125. extern Time time_TwoSeconds;
  126. extern Time time_TenSeconds;
  127. extern Time time_OneMinute;
  128. extern Time time_OneHour;
  129. extern Time time_OneDay;
  130. extern Time time_OneYear;
  131. extern Time time_OneLeapYear;
  132.  
  133.  
  134. /* PROCEDURES */
  135.  
  136. extern void    Time_Add _ARGS_((Time time1, Time time2, Time *resultPtr));
  137. extern void    Time_Subtract _ARGS_((Time time1, Time time2,
  138.                       Time *resultPtr));
  139. extern void    Time_Multiply _ARGS_((Time time, int factor, Time *resultPtr));
  140. extern void    Time_Divide _ARGS_((Time time, int factor, Time *resultPtr));
  141. extern void    Time_Normalize _ARGS_((Time *timePtr));
  142. extern void    Time_ToAscii _ARGS_((int time, Boolean relativeTime,
  143.                      char *bufferPtr));
  144. extern void    Time_ToParts _ARGS_((int time, Boolean relativeTime,
  145.                      Time_Parts *partsPtr));
  146.  
  147.  
  148. /*
  149.  *----------------------------------------------------------------------
  150.  *
  151.  * Time Comparisons --
  152.  *
  153.  *    Time_LT:    time1  <   time2
  154.  *    Time_LE:    time1  <=  time2
  155.  *    Time_EQ:    time1  ==  time2
  156.  *    Time_GE:    time1  >=  time2
  157.  *    Time_GT:    time1  >   time2
  158.  *
  159.  * Results:
  160.  *     TRUE    - the relation holds for the 2 values.
  161.  *     FALSE    - the relation does not hold.
  162.  *
  163.  * Side effects:
  164.  *     None.
  165.  *
  166.  *----------------------------------------------------------------------
  167.  */
  168.  
  169. #define Time_LT(time1, time2) \
  170.         (((time1).seconds     <  (time2).seconds) ||  \
  171.          (((time1).seconds     == (time2).seconds) &&  \
  172.           ((time1).microseconds <  (time2).microseconds)))
  173.  
  174. #define Time_LE(time1, time2) \
  175.         (((time1).seconds     <  (time2).seconds) ||  \
  176.          (((time1).seconds     == (time2).seconds) &&  \
  177.           ((time1).microseconds <= (time2).microseconds)))
  178.  
  179. #define Time_EQ(time1, time2) \
  180.         (((time1).seconds     == (time2).seconds) &&  \
  181.          ((time1).microseconds == (time2).microseconds))
  182.  
  183. #define Time_GE(time1, time2) \
  184.         (((time1).seconds     >  (time2).seconds) ||  \
  185.          (((time1).seconds     == (time2).seconds) &&  \
  186.           ((time1).microseconds >= (time2).microseconds)))
  187.  
  188. #define Time_GT(time1, time2) \
  189.         (((time1).seconds     >  (time2).seconds) ||  \
  190.          (((time1).seconds     == (time2).seconds) &&  \
  191.           ((time1).microseconds >  (time2).microseconds)))
  192.  
  193.  
  194. /*
  195.  *----------------------------------------------------------------------
  196.  *
  197.  * Time_ToMs --
  198.  *
  199.  *    Convert a time value (usually a small interval) to a floating-point 
  200.  *    number of milliseconds.
  201.  *
  202.  * Results:
  203.  *    Returns a float.
  204.  *
  205.  * Side effects:
  206.  *    None.
  207.  *
  208.  *----------------------------------------------------------------------
  209.  */
  210.  
  211. #define Time_ToMs(time)    ((float)(time).seconds * 1000 + \
  212.              (float)(time).microseconds / 1000)
  213.  
  214.  
  215. /*
  216.  *----------------------------------------------------------------------
  217.  *
  218.  * Time_Average --
  219.  *
  220.  *    Return the average time from some total.
  221.  *
  222.  * Results:
  223.  *    Returns the total time divided by the given count.  Returns 0 if 
  224.  *    the count is 0.  Be sure to cast this if total is a float.
  225.  *
  226.  * Side effects:
  227.  *    None.
  228.  *
  229.  *----------------------------------------------------------------------
  230.  */
  231.  
  232. #define Time_Average(total, count) ((count) == 0 ? 0 : (total) / (count))
  233.  
  234. #endif /* _SPRITETIME */
  235. @
  236.  
  237.  
  238. 1.4
  239. log
  240. @Use function prototypes.
  241. @
  242. text
  243. @d15 1
  244. a15 1
  245.  * rcsid: $Header: /sprite/src/lib/include/RCS/spriteTime.h,v 1.3 89/06/23 11:30:25 rab Exp Locker: kupfer $ SPRITE (Berkeley)
  246. d144 41
  247. @
  248.  
  249.  
  250. 1.4.1.1
  251. log
  252. @Initial branch for Sprite server.
  253. @
  254. text
  255. @d15 1
  256. a15 1
  257.  * rcsid: $Header: /sprite/src/lib/include/RCS/spriteTime.h,v 1.4 90/09/11 14:40:15 kupfer Exp $ SPRITE (Berkeley)
  258. @
  259.  
  260.  
  261. 1.3
  262. log
  263. @*** empty log message ***
  264. @
  265. text
  266. @d15 1
  267. a15 1
  268.  * rcsid: $Header: /sprite/src/lib/include/RCS/spriteTime.h,v 1.2 88/07/29 18:05:57 ouster Exp Locker: rab $ SPRITE (Berkeley)
  269. d88 10
  270. a97 7
  271. extern void     Time_Add();
  272. extern void     Time_Subtract();
  273. extern void     Time_Multiply();
  274. extern void     Time_Divide();
  275. extern void     Time_Normalize();
  276. extern void    Time_ToAscii();
  277. extern void    Time_ToParts();
  278. d123 2
  279. a124 2
  280.         (((time1).seconds     == (time2).seconds) &&  \
  281.         ((time1).microseconds <  (time2).microseconds)))
  282. d128 2
  283. a129 2
  284.         (((time1).seconds     == (time2).seconds) &&  \
  285.         ((time1).microseconds <= (time2).microseconds)))
  286. d133 1
  287. a133 1
  288.         ((time1).microseconds == (time2).microseconds))
  289. d137 2
  290. a138 2
  291.         (((time1).seconds     == (time2).seconds) &&  \
  292.         ((time1).microseconds >= (time2).microseconds)))
  293. d142 2
  294. a143 2
  295.         (((time1).seconds     == (time2).seconds) &&  \
  296.         ((time1).microseconds >  (time2).microseconds)))
  297. @
  298.  
  299.  
  300. 1.2
  301. log
  302. @Change #ifdef identifier to match file name.
  303. @
  304. text
  305. @d15 1
  306. a15 1
  307.  * rcsid: $Header: spriteTime.h,v 1.1 88/06/21 16:34:14 ouster Exp $ SPRITE (Berkeley)
  308. d142 1
  309. a142 1
  310. #endif _SPRITETIME
  311. @
  312.  
  313.  
  314. 1.1
  315. log
  316. @Initial revision
  317. @
  318. text
  319. @d15 1
  320. a15 1
  321.  * rcsid: $Header: time.h,v 1.1 88/06/21 09:37:00 ouster Exp $ SPRITE (Berkeley)
  322. d18 2
  323. a19 2
  324. #ifndef _TIME
  325. #define _TIME
  326. d142 1
  327. a142 1
  328. #endif _TIME
  329. @
  330.